package www.wxwnb.clerk.http;

import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;

import java.net.URLConnection;
import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import www.wxwnb.clerk.utils.UrlConnect;

/**
 * Created by dingguanxu on 2017/9/11.
 */

public class HttpMethods {

    private static final int DEFAULT_TIMEOUT = 5;
//    private static final String BASE_URL = "http://192.168.2.202:8080/offcialbackstage/";

    public Retrofit mRetrofit;

    //私有构造方法
    private HttpMethods() {
        OkHttpClient.Builder builder = new OkHttpClient.Builder();
        builder.connectTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS);
        mRetrofit = new Retrofit.Builder()
                .client(builder.build())
//                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .addConverterFactory(GsonConverterFactory.create())
                .baseUrl(UrlConnect.BASE_URL)
                .build();
    }

    //访问的时候创建单列
    private static class SingletonHolder {
        private static final HttpMethods INSTANCE = new HttpMethods();
    }

    //获取单例
    public static HttpMethods getInstance () {
        return SingletonHolder.INSTANCE;
    }
}
